package com.game.rpc;

import java.lang.reflect.Method;

import com.game.share.IOPackage;
import com.game.share.StreamReader;

public class ServiceExcutor {
	
	public ServiceExcutor(Class<RemoteService> serviceClass) {

	}

	public IOPackage execute(Class<? extends RemoteService> serviceClass,
			RemoteService service, StreamReader param) throws Exception {
		String methodName = param.readString();
		Method[] methodList = serviceClass.getMethods();
		for (Method method : methodList) {
			Class<?>[] paramTypes = method.getParameterTypes();
			// 只检查函数名，不检查参数类型个数
			if (method.getName().equals(methodName)) {
				// execute
				Object[] args = new Object[paramTypes.length];
				for (int i = 0; i < paramTypes.length; i++) {
					if (paramTypes[i].equals(String.class)) {
						args[i] = param.readString();
					} else if (paramTypes[i].equals(Integer.class)) {
						args[i] = param.readInt();
					} else if (paramTypes[i].isArray()) {
						// TODO
					}
				}
//				Object object = method.invoke(service, args);
			}
		}

		return null;
	}

}
